"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.userOnlineState = void 0;
const defines_1 = require("../../lib/defines");
const utils_1 = require("../../utils/utils");
const log4js_1 = require("log4js");
const Member_1 = require("../../lib/Member");
const logger = (0, log4js_1.getLogger)('socket/user:online_state');
function userOnlineState(app) {
    const { socket } = app.locals;
    const { userId, username } = socket.handshake.query;
    socket.use(async (event, next) => {
        const [name, params] = event;
        logger.debug('=================>', name);
        if (name === defines_1.RequestMethod.login) {
            logger.debug('login: =>', `user：{ ${userId}, ${username} }`);
            const owner = Member_1.Members.get(userId);
            owner.axios.toggleAccountState(userId, 1).then((res) => {
                socket.emit('登录状态改变: => ', res);
                logger.debug(`用户 ${(0, utils_1.stringify)({ userId, username })} 登录状态改变成功！status: 1`);
            });
        }
        next();
    });
}
exports.userOnlineState = userOnlineState;
